var Viamagus_Form_Loader={isAllEmailAddressAreValid:true,_contextPath:'',_productQtyInfo:[],_init:function(){var that=this;if($('.viamagus-custom-form').length){that._loadCustomForms();that._initDatePicker();that._additionalValidations();that._initRatings();that._initGoogleMap();that._initGoogleDistanceCalculator();that._initAddressCountryStateCityLoad();} that._initPhonePlugin();that._initEmailOTPGenerateEvents();that._initCombobox();this._initPaymentForm();},_ipInfoResult:null,_loadCustomForms:function(){var that=this;if($('.viamagus-custom-form').length){$('.viamagus-custom-form').each(function(index,e){var customformId=$(e).attr('id');var index=customformId.lastIndexOf('-');var formId=customformId.substring(index+1,customformId.length);var url=that._contextPath+'/REST/formbuilder/loadCustomFormMetadata';$.ajax({url:url,data:{formId:formId},dataType:'jsonp',jsonp:'jsonCallback'}).done(function(data){that._initCustomFormFileUpload(data.result.tenantId);if(data.result){var formMetaData=data.result;$('#'+customformId).unbind();Viamagus_Form_Loader._validate(customformId,formMetaData);$('#'+customformId).submit(function(event){event.preventDefault();var validator=$('#'+customformId).validate();if($('#'+customformId).valid()){if(data.result.isPaymentRequired=='Y'&&data.result.allowCustomPayment=='N'&&!that._validateProductDetails()){return false;} Viamagus_Form_Loader._submitFormAfterValidation(formId,formMetaData);}});if(data.result.isPaymentRequired=='Y'&&data.result.allowCustomPayment=='N'){if(!$(".vm-currency-container")||$(".vm-currency-container").length==0){Viamagus_Currency_Manager.txnCurrency=data.result.baseCurrency;} that._registerProductCalculataionEvent(formId,data.result.baseCurrency);}else{that._loadCustomPaymentCurrencyList();}}}).fail(function(){});});}},_saveCustomFormValues:function(formId,customFormJSON,formType,formData,crmName,crmEmailId,crmPhoneNo,allowCustomPayment,paymentAmount,customPaymentProductInfo,formPaymentCurrency,crmAddress){var that=this;var isPaymentRequired=formData.isPaymentRequired;var productJSON="";if(isPaymentRequired=='Y'){productJSON=that._buildProductJSON();} var html='' $('#viamagus-form-'+formId).find('#Submit').parent().append(html);$('#viamagus-form-'+formId).find('#Submit').text('Submitting....');$('#viamagus-form-'+formId).find('#loaderImageForSubmit').show();var forwardToCustomUrl=formData.forwardToCusotmUrl;var that=this;var successMsg=formData.ackMsg;if(successMsg==null||successMsg==''){successMsg='Thank you!';} var reqOptions={url:that._contextPath+'/REST/formbuilder/saveCustomFormValues',data:{format:'json',type:'POST',formId:formId,formJson:encodeURIComponent(customFormJSON),formType:formType,productJSON:productJSON,websiteUrl:window.location.href,isPaymentRequired:isPaymentRequired,isCustomPayment:allowCustomPayment,paymentAmount:paymentAmount,paymentCurrency:formPaymentCurrency},callback:function(data,formSubmitLogId){if(forwardToCustomUrl!=""&&forwardToCustomUrl!=null){window.location.href=forwardToCustomUrl;}else if(isPaymentRequired=='Y'){$('#loaderImageForSubmit').remove();$('#viamagus-form-'+formId).find('#Submit').text('Submit');var url=that._contextPath+"/paymentCapture.html";var discountCode='';var discountAmount='';var productName='Custom Payment';var paymentCurrency='INR';if(allowCustomPayment=='N'){discountCode=JSON.parse(productJSON).discountCode;discountAmount=JSON.parse(productJSON).discountAmount;productName=JSON.parse(productJSON).prodcutName;}else{productName=customPaymentProductInfo;} if(formPaymentCurrency!=''){paymentCurrency=formPaymentCurrency;} that.submitToUrl(url,{isPaymentReqd:"Y",productName:productName,productAmount:paymentAmount,isProductEditable:false,isPriceEditable:false,customerName:crmName,customerEmail:crmEmailId,customerPhoneNo:crmPhoneNo,entityType:'Form',entityId:formSubmitLogId,discountCode:discountCode,discountAmount:discountAmount,paymentCurrency:paymentCurrency,addressLineOne:crmAddress.addressLineOne,addressLineTwo:crmAddress.addressLineTwo,city:crmAddress.city,state:crmAddress.state,country:crmAddress.country,pincode:crmAddress.pincode});}else{$('#loaderImageForSubmit').remove();$('#viamagus-form-'+formId).find('#Submit').text('Submit');if($('#showAckModal').length!=0){$('body').remove('#showAckModal');} var modalHtml='';$('body').append(modalHtml);$('#showAckModal').modal('show');Viamagus_Form_Loader._resetFormValues(formData);}},errorCallBack:function(){$('#loaderImageForSubmit').remove();$('#viamagus-form-'+formId).find('#Submit').text('Submit');if($('#showAckModal').length!=0){$('body').remove('#showAckModal');} var modalHtml='';if(!$('#alert-message').length){$('body').append(modalHtml);$('#showAckModal').modal('show');}},async:false};new viamagusTransactionManager(reqOptions);},_initDatePicker:function(){var that=this;$('.viamagus-date-picker').each(function(){var dateobj=$(this).pickmeup({position:'bottom',hide_on_select:true,view:'years',calendars:1,format:'d-b-Y',minDate:0,change:function(e){console.log("date changed");$(this).trigger('blur');}});});$('.viamagus-date-picker-icon').click(function(e){e.preventDefault();var id=$(this).attr("data-date-picker");$('#'+id).trigger('click');});},_validate:function(id,formData){var that=this;var json='{';var newJson={};var formMetaData=formData.metadataDetailsList;for(var i=0;i').parent().html();$('#'+id).remove();$(element).parent().parent().append(newhtml);}else if($(element).hasClass("viamagus-combobox")){var labelId=$(element).parent().find('label').attr('id');var html=$(element).parent().find('label').css('color','red');newhtml=(html).wrap('
').parent().html();$('#'+labelId).remove();$(element).css("border","1px solid red");$(newhtml).insertAfter($(element).parent());}else if($(element).hasClass("viamagus-date-picker")){$(element).css("border","1px solid red");$(element).parent().find('label').css('color','red');var id=$(element).parent().find('label').attr('id');var html=$(element).parent().find('label');newhtml=(html).wrap('
').parent().html();$('#'+id).remove();$(element).parent().parent().append(newhtml);}else{$(element).css("border","1px solid red");$(element).parent().find('label').css('color','red');}},unhighlight:function(element,errorClass,validClass){$(element).css("border","1px solid #ccc");}});},_additionalValidations:function(){jQuery.validator.addMethod("alphanumeric",function(value,element){return this.optional(element)||/^[a-zA-Z0-9 ]*$/.test(value);},"Please enter alpha numeric characters");jQuery.validator.addMethod("alpha",function(value,element){return this.optional(element)||/^[a-zA-Z ]*$/.test(value);},"Please enter only alphabets characters");jQuery.validator.addMethod("decimal",function(value,element){return this.optional(element)||/^[0-9]+(\.[0-9])?$/.test(value);},"Please enter only decimal numbers");},_submitFormAfterValidation:function(formId,formData){var that=this;var jsonString='{ "formJson": { "customValues": [';var isRequired='N';var isFileUploadRequired=false;var isValidPhoneNo=true;var isValidEmail=true;var isValidSrcDstSelected=true;var isValidCheckBox=true;var formType='';var formMetaData=formData.metadataDetailsList;var crmEmailId='';var crmName='';var crmPhoneNo='';var crmAddress={addressLineOne:'',addressLineTwo:'',city:'',state:'',country:'',pincode:''};var allowCustomPayment="N";var paymentAmount=0;var customPaymentProductInfo="";var paymentCurrency="INR";for(var i=0;i0) fieldValue=val.substr(0,val.length-1);break;case "multipleradios":var val='';$('input[name='+fieldId+']').each(function(){if($(this).is(":checked")){val=val+$(this).val();val=val+",";}});if(val.length>0) fieldValue=val.substr(0,val.length-1);break;case "multipleradiosinline":var val='';$('input[name='+fieldId+']').each(function(){if($(this).is(":checked")){val=val+$(this).val();val=val+",";}});if(val.length>0) fieldValue=val.substr(0,val.length-1);break;case "multiplecheckbox":var val='';var minChkReqd=0;var maxChkReqd=0;var totalChk=0;$('input[name='+fieldId+']').each(function(){minChkReqd=$(this).attr("data-min-chk-reqd");maxChkReqd=$(this).attr("data-max-chk-reqd");if($(this).is(":checked")){totalChk=totalChk+1;val=val+$(this).val();val=val+",";}});if(minChkReqd>0){if(totalChk0){if(totalChk>maxChkReqd){$('#max-chk-error-msg-'+fieldId).show();isValidCheckBox=false;$('input[name='+fieldId+']')[0].focus();}else{$('#max-chk-error-msg-'+fieldId).hide();}} if(val.length>0) fieldValue=val.substr(0,val.length-1);break;case "multiplecheckboxinline":var val='';var minChkReqd=0;var maxChkReqd=0;var totalChk=0;$('input[name='+fieldId+']').each(function(){minChkReqd=$(this).attr("data-min-chk-reqd");maxChkReqd=$(this).attr("data-max-chk-reqd");if($(this).is(":checked")){totalChk=totalChk+1;val=val+$(this).val();val=val+","}});if(minChkReqd>0){if(totalChk0){if(totalChk>maxChkReqd){$('#max-chk-error-msg-'+fieldId).show();isValidCheckBox=false;$('input[name='+fieldId+']')[0].focus();}else{$('#max-chk-error-msg-'+fieldId).hide();}} if(val.length>0) fieldValue=val.substr(0,val.length-1);break;case "productList":if(fieldLabel=='Product Payment Amount'){fieldValue=$('#totalAmountToPay').html()+" INR";if(formData.allowCustomPayment=='N'){paymentAmount=$('#totalAmountToPay').attr("data-total-amount");}}else{fieldValue="";} if(Viamagus_Currency_Manager.txnCurrency!=''){if(formData.allowCustomPayment=='N'){paymentCurrency=Viamagus_Currency_Manager.txnCurrency;paymentAmount=$('#totalAmountToPay').attr("data-total-amount-in-txn-cur");} fieldValue=$('#totalAmountToPay').html()+" "+paymentCurrency;} break;case "custompayment":fieldValue=$('#'+fieldId).val()+' '+$('#'+fieldId+'-currency option:selected').val();allowCustomPayment="Y";paymentCurrency=$('#'+fieldId+'-currency option:selected').val();customPaymentProductInfo=$('#'+fieldId).attr("data-product-info");paymentAmount=$('#'+fieldId).val();break;} jsonString=jsonString+'"fieldValue": "'+fieldValue+'",';jsonString=jsonString+'"isCrmField": "'+isCrmField+'",';jsonString=jsonString+'"crmFieldType": "'+crmFieldType+'",';jsonString=jsonString+'"metaDataId": "'+metaDataId+'"';jsonString=jsonString+'},';} jsonString=jsonString+']}}';if(ratings==0&&isRequired=='Y'){alert("Rating is required.");return;} if(!isValidPhoneNo||!isValidCheckBox||!isValidSrcDstSelected||!isValidEmail){return;} if(!that.isAllEmailAddressAreValid){alert("Please enter a valid email Id.");return;} if(isFileUploadRequired){alert("Please choose a file to upload.");return;} if(!that.invokeCustomFormValidation()){return;} if(formData.isAutoReplyMsgReqd!=""&&formData.isAutoReplyMsgReqd!=null&&formData.isAutoReplyMsgReqd!='undefined'&&formData.isAutoReplyMsgReqd=='Y'){if($('#showConfirmModal').length>0){$('#showConfirmModal').remove();} var modalHtml='';$('body').append(modalHtml);$('#showConfirmModal').modal('show');$('#showConfirmModal #confirm').unbind();$('#showConfirmModal #confirm').click(function(e){e.preventDefault();Viamagus_Form_Loader._saveCustomFormValues(formId,jsonString,formType,formData,crmName,crmEmailId,crmPhoneNo,allowCustomPayment,paymentAmount,customPaymentProductInfo,paymentCurrency,crmAddress);});}else{Viamagus_Form_Loader._saveCustomFormValues(formId,jsonString,formType,formData,crmName,crmEmailId,crmPhoneNo,allowCustomPayment,paymentAmount,customPaymentProductInfo,paymentCurrency,crmAddress);}},_initRatings:function(){$('.viamagus-star-rating').each(function(){var stars=$(this).attr("data-number");$(this).raty({number:stars,click:function(score,evt){$(this).attr('data-score',score);},hints:[]});});},_initCustomFormFileUpload:function(tenantId){var that=this;if($('.viamagus-file-upload').length){$.ajax({type:'POST',url:'/cdnupload/json/initContainerForCustomFormFileUpload.action',data:{tenantId:tenantId},success:function(data){that.initDropzoneForAjaxFileUpload(data.transactionRefNo);}});}},initDropzoneForAjaxFileUpload:function(transactionId){$('.viamagus-file-upload').each(function(index,e){var fileuploadId="#"+$(e).attr("id");var myDropzone=new Dropzone(fileuploadId,{autoProcessQueue:true,paramName:'upload',uploadMultiple:false,maxFilesize:5,maxFiles:1,accept:function(file,done){debugger;$(fileuploadId).attr("data-file-name",transactionId+"-"+file.name.replace(/[^a-zA-Z0-9.]/g,''));$('#Submit').prop('disabled',true) done();},complete:function(){$('#Submit').prop('disabled',false);},url:'/cdnupload/uploadCustomFormUserFile.action?transactionId='+transactionId,thumbnailWidth:"50",thumbnailHeight:"50",previewsContainer:".file-preview",init:function(){var myDropzone=this;this.on("addedfile",function(){if(this.files[1]!=null){this.removeFile(this.files[0]);}});}});});},_resetFormValues:function(formData){var formMetaData=formData.metadataDetailsList;for(var i=0;i").attr("id",emailIdObj.attr('id')+"-error-api").css('color','red').html("Email address does not exist.");if($('#'+emailIdObj.attr('id')+"-error-api").length==0){place.insertAfter(emailIdObj);} emailIdObj.css("border","1px solid red");Viamagus_Form_Loader.isAllEmailAddressAreValid=false;}},showInValidEmailMessage:function(emailIdObj,data){emailIdObj.css("border","");$('#'+emailIdObj.attr('id')+"-error").remove();Viamagus_Form_Loader.isAllEmailAddressAreValid=true;if(!data['is_valid']){var place=$("